<style lang="less" scoped>
  .f-ec-sy {
    margin-top: 10px;
  }

  .la-sy {
    color: red;
  }

  .p-sy {
    margin-top: 0px;
    margin-bottom: 0px;
  }

  .f-w80 {
    position: absolute;
    margin-top: -6px;
    width: 80px;
  }

  .el-menu {
    background: #f2f2f2;
  }
</style>
<template>
  <div>
    <el-row>
      <el-col :span="24">
        <div class="grid-content" style="background-color: #f2f2f2">
          <el-row>
            <el-col :span="12">
              <div class="grid-content">
                <el-menu :default-active="orderPayments" class="el-menu-demo" mode="horizontal"
                         @select="activeOrderPaymentsClick">
                  <el-menu-item index="all">全部</el-menu-item>
                  <el-menu-item v-for="(op,index) in $store.getters.PAY_WAY" :index="op.dictVal.toString()" :key="index">{{op.cnDictValname}}
                  </el-menu-item>
                </el-menu>
              </div>
            </el-col>
            <el-col :span="12" style="line-height: 60px">
              <el-checkbox v-model="collection">显示有代收货款的订单</el-checkbox>
              <el-checkbox v-model="support">显示有保价金额的订单</el-checkbox>
            </el-col>
          </el-row>
          <ue-search-bar ref="ueSearchBar" v-model="searchForm" :data="querys" label-width="120px">
          </ue-search-bar>
        </div>
      </el-col>
    </el-row>
    <el-row>
      <el-col :span="24">
        <div class="grid-content">
        </div>
      </el-col>
    </el-row>
    <el-row>
      <el-col :span="5" class="f-ec-sy f-mb5">
        <el-button type="primary" class="f-wa f-fl" @click="accountMonthly">按月销账</el-button>
        <el-button type="primary" class="f-wa f-fl">打印</el-button>
        <el-button type="primary" class="f-wa f-fl" @click="exportOrderReceivableStatisticsData">导出</el-button>
        <el-button type="primary" class="f-wa f-fl" @click="monthlyBillExport">月账单导出</el-button>
      </el-col>
      <el-col :span="14" class="f-ec-sy f-mb5">
        <label style="margin-left: 10%">
          当前选中 <label> {{selectRows.length}} 条，</label>
          应收订单总额 <label class="la-sy" v-html="seYSHtml"></label>元，
          已收订单总额 <label class="la-sy" v-html="seYESHtml"></label>元，
          剩余订单总额 <label class="la-sy" v-html="seSYHtml"></label>元
        </label>
        <br>
        <label style="margin-left: 10%">
          当前选中 <label> {{selectRows.length}} 条，</label>
          应收货代总额 <label class="la-sy" v-html="dsseYSHtml"></label>元，
          已收货代总额 <label class="la-sy" v-html="dsseYESHtml"></label>元，
          剩余货代总额 <label class="la-sy" v-html="dsseSYHtml"></label>元
        </label>
      </el-col>
      <el-col :span="5" class="f-ec-sy f-mb5">
        <el-button type="primary" class="f-wa f-fr" @click="resetSearch">重置</el-button>
        <el-button type="primary" class="f-wa f-fr f-mr10" @click="resetSearchOrders">查询</el-button>
      </el-col>

    </el-row>
    <el-row>
      <el-col :span="24">
        <div class="grid-content">
          <el-table
            :data="orderReceivableStatisticsTableData" border
            max-height="600"
            @selection-change="selectionOrderChange">
            <el-table-column
              type="selection"
              width="55">
            </el-table-column>
            <el-table-column prop="date" label="订单编号" width="145">
              <template slot-scope="scope">
                <a @click="seOrderClick(scope.row)"
                   style="cursor: pointer;text-decoration:underline;color: #20a0ff">{{scope.row.orderNumber}}</a>
              </template>
            </el-table-column>
            <el-table-column prop="name" label="日期" width="180">
              <template slot-scope="scope">
                下单时间:<label>{{scope.row.createDate.substring(0, 10)}}</label><br>
                发车时间:<label
                v-if="scope.row.actualDepartureDate != null">{{scope.row.actualDepartureDate.substring(0, 10)}}</label><br>
                签收时间:<label v-if="scope.row.signOffDate !=null">{{scope.row.signOffDate.substring(0, 10)}}</label><br>
              </template>
            </el-table-column>
            <el-table-column prop="memberUserName" label="名称" width="190">
              <template slot-scope="scope">
                客户名称:<label>{{scope.row.memberUserName}}</label><br>
                发货人名称:<label>{{scope.row.shipmentsContactName}}</label>
              </template>
            </el-table-column>
            <el-table-column label="专线组织（承运商）" width="170">
              <template slot-scope="scope">
                专线组织:<label>{{scope.row.currentSpecialLineNames}}</label><br>
                车辆信息:<label>{{scope.row.carInfo}}</label><br>
                司机姓名:<label>{{scope.row.driverName}}</label>
              </template>
            </el-table-column>
            <el-table-column prop="shipmentsAddress" label="地址" width="200">
              <template slot-scope="scope">
                <label><label class="la-sy">起</label>:{{scope.row.shipmentsAddress}}</label><br>
                <label><label class="la-sy">止</label>:{{scope.row.sendAddress}}</label>
              </template>
            </el-table-column>
            <el-table-column prop="taxsheet" label="发票信息"></el-table-column>
            <el-table-column prop="supportValue" label="保价金额">

            </el-table-column>
            <el-table-column prop="collectionDelivery" label="代收货款">
              <template slot-scope="scope">
                <label>{{scope.row.collectionDelivery}}</label><br>
                <label v-if="scope.row.collectionDeliveryStatusName===102004001">待付款</label>
                <label v-if="scope.row.collectionDeliveryStatusName===102004002">已付款</label>
              </template>
            </el-table-column>
            <el-table-column label="状态" width="180">
              <template slot-scope="scope">
                <p class="p-sy">订单状态：{{scope.row.orderStatusName}}</p>
                <p class="p-sy" v-if="scope.row.signOff===101009001">签收状态：未签收</p>
                <p class="p-sy" v-if="scope.row.signOff===101009002">签收状态：已签收</p>
                <p class="p-sy" v-if="scope.row.actualDeparture">发车状态：已发车</p>
                <p class="p-sy" v-if="!scope.row.actualDeparture">发车状态：未发车</p>
                <p class="p-sy ">结算方式：{{scope.row.paymentTypeName}}</p>
                <p class="p-sy ">付款方式：{{scope.row.orderPays}}</p>
              </template>
            </el-table-column>
            <el-table-column prop="orderPrice" label="订单结算" width="150">
              <template slot-scope="scope">
                <label>订单金额:{{parseFloat(scope.row.orderPrice).toFixed(2)}}</label><br>
                <label>优惠金额:{{scope.row.couponPrice}}</label><br>
                <label
                  v-if="scope.row.receivedPrice !=null">已付金额:{{parseFloat(scope.row.receivedPrice).toFixed(2)}}</label><br>
                <label>支付状态:{{scope.row.payStatusName}}</label><br>
              </template>
            </el-table-column>
            <el-table-column prop="address" label="操作" width="95">
              <template slot-scope="scope">
                <el-button type="primary" class="f-wa f-mt5 f-mb5"
                           v-if="(scope.row.orderPricePayStatus===102004001)||(scope.row.collectionDelivery!==null&&scope.row.collectionDeliveryStatusName===102004001)"
                           @click="cancelAccountClick(scope.row)">销账
                </el-button>
                <el-button type="primary" class="f-wa f-mt5 f-mb5" style="margin-left: 0"
                           v-if="(scope.row.orderPricePayStatus===102004001)||(scope.row.collectionDelivery!==null&&scope.row.collectionDeliveryStatusName===102004001)"
                           @click="paymentConfirmation(scope.row)">收款确认
                </el-button>
                <el-button type="primary" class="f-wa f-mt5 f-mb5"
                           v-if="(scope.row.orderPricePayStatus===102004002)||(scope.row.collectionDelivery!==null&&scope.row.collectionDeliveryStatusName===102004002)"
                           @click="selectGatheringRecord(scope.row)">收款记录
                </el-button>
              </template>
            </el-table-column>
          </el-table>
          <el-row style="margin-top: 10px">
            <el-col :span="12">
              <label>
                总计：
                应收订单总额 <label class="la-sy" v-html="totalYSHtml"></label>元，
                已收订单总额 <label class="la-sy" v-html="totalYESHtml"></label>元，
                剩余订单总额 <label class="la-sy" v-html="totalSYHtml"></label>元
              </label>
              <br>
              <label>
                总计：
                应收货代总额 <label class="la-sy" v-html="dstotalYSHtml"></label>元，
                已收货代总额 <label class="la-sy" v-html="dstotalYESHtml"></label>元，
                剩余货代总额 <label class="la-sy" v-html="dstotalSYHtml"></label>元
              </label>
            </el-col>
            <el-col :span="12">
              <el-pagination
                :current-page="currentPage"
                :page-size="pageSize"
                :page-sizes="[6, 15, 30, 100]"
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
                layout="total,sizes,prev, pager, next, jumper"
                :total="total" style="float: right">
              </el-pagination>
            </el-col>
          </el-row>
        </div>
      </el-col>
    </el-row>
    <!--订单查看Dialog-->
    <el-dialog title="订单查看" :visible.sync="orderSelect" width="80%">
      <order-select :title="orderSelectForm"></order-select>
    </el-dialog>
    <!--销账Dialog-->
    <el-dialog :title="cancelAccountDialogTitle" :visible.sync="cancelAccountDialog" size="tiny">
      <el-form ref="cancelAccountForm" :model="cancelAccountForm" label-width="80px">
        <el-form-item label="销账项目" prop="gatheringType" :rules="[{validator: this.gatheringTypeFun}]">
          <el-checkbox-group v-model="gatheringTypes" @change="checkClick">
            <el-checkbox v-if="clickRow.orderPricePayStatus===102004001" label="0">
              订单金额
            </el-checkbox>
            <el-checkbox
              v-if="clickRow.collectionDelivery!==null&&clickRow.collectionDeliveryStatusName===102004001"
              label="1">代收货款
            </el-checkbox>
          </el-checkbox-group>
        </el-form-item>
        <el-form-item label="收款金额">
          <el-input class="f-w70" v-model="cancelAccountForm.rTotal" disabled></el-input>
        </el-form-item>
        <el-form-item label="收款人" prop="receivedUser" :rules="[{required: true, message: '请输入收款人', trigger: 'change'}]">
          <el-input class="f-w70" v-model="cancelAccountForm.receivedUser"></el-input>
        </el-form-item>
        <el-form-item label="收款时间" prop="receivedDate"
                      :rules="{required: true, type: 'date',message: '请选择收款时间', trigger: 'change'}">
          <el-date-picker style="width: 70%"
                          v-model="cancelAccountForm.receivedDate"
                          type="datetime"
                          placeholder="选择收款时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="备注信息">
          <el-input class="f-w70" type="textarea" v-model="cancelAccountForm.remark"></el-input>
        </el-form-item>
        <el-form-item label="交易凭证">
          <el-upload class="el-upload-wh"
                     :on-success="handleAvatarSuccess"
                     action="/api/v2.0/admin/file_upload"
                     ref="upload"
                     :file-list="fileList"
                     list-type="picture-card"
                     :before-upload="beforeAvatarUpload">
            <i class="el-icon-plus"></i>
          </el-upload>
          <el-dialog :visible.sync="dialogVisible" size="tiny">
            <img width="50%" style="width: 40%" :src="dialogImageUrl" alt>
          </el-dialog>
          <label>只能上传jpg/png文件，且文件不超过2M</label>
        </el-form-item>
        <el-form-item>
          <el-button @click="cancelAccountDialog = false">取消</el-button>
          <el-button type="primary" @click="saveCancelAccountBtn">确认</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
    <el-dialog title="付款确认" size="tiny" :visible.sync="paymentConfirmationDialog">
      <div style="background: #F2F2F2;">
        <el-row class="f-pt10 f-mb0">
          <el-col :span="12">
            <div class="grid-content f-ml10">订单编号：<label v-html="orderNumberPayHtml"></label></div>
          </el-col>
          <el-col :span="12">
            <div class="grid-content">订单运费：<label v-html="orderFreight"></label></div>
          </el-col>
        </el-row>
        <el-row class="f-mb0">
          <el-col :span="12">
            <div class="grid-content f-ml10">结算方式：<label v-html="orderPaymentType"></label></div>
          </el-col>
          <el-col :span="12">
            <div class="grid-content">代收货款：<label v-html="collectPaymentAmount"></label></div>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <div class="grid-content bg-purple-dark f-ml10 f-cr">应收总金额：<label
              v-html="orderTotalMoney"></label></div>
          </el-col>
        </el-row>
      </div>
      <el-row class="f-mb0" style="display: none">
        <el-col :span="24" class="f-ml10 f-mt10">
          <div class="grid-content bg-purple-dark">
            <el-radio class="radio" v-model="orderPayRadio" label="accountPay"> 账户余额：可支付余额: 0元
            </el-radio>
          </div>
        </el-col>
      </el-row>
      <el-row class="f-mb0">
        <el-col :span="24" class="f-ml10">
          <div class="grid-content bg-purple-dark">其他支付方式</div>
        </el-col>
      </el-row>
      <el-row style="background: #F2F2F2;">
        <el-col :span="24" class="f-mb20 f-ml10">
          <div class="grid-content bg-purple-dark">
            <div class="grid-content">
              <div>
                <p>请选择以下支付方式的一种</p>
                <el-row class="f-pb10 f-pl10">
                  <el-col :span="8">
                    <el-radio class="radio" v-model="orderPayRadio" label="aliPay">
                      <img src="../../assets/aliPayLogo.png" class="f-w80"></el-radio>
                  </el-col>
                  <el-col :span="8">
                    <el-radio class="radio" v-model="orderPayRadio" label="weChatPay"><img
                      src="../../assets/weChatLogo.png" class="f-w80"></el-radio>
                  </el-col>
                  <el-col :span="8">
                    <el-radio class="radio" v-model="orderPayRadio" label="unionPay"><img
                      src="../../assets/unionPayLogo.png" class="f-w80"></el-radio>
                  </el-col>
                </el-row>
              </div>
            </div>
          </div>
        </el-col>
      </el-row>
      <span slot="footer" class="dialog-footer">
                <el-button @click="paymentConfirmationDialog = false" class="f-wa">取 消</el-button>
                <el-button type="primary" @click="paymentAffirms" class="f-wa">确 定</el-button>
            </span>
    </el-dialog>
    <el-dialog title="请使用微信客户端扫一扫支付" :visible.sync="wechatQRCodeDialog"
               size="tiny">
      <div v-html="QRCodehtml">
      </div>
    </el-dialog>
    <!--收款记录Dialog-->
    <el-dialog title="收款记录" :visible.sync="selectGatheringRecordDialog" size="tiny">
      <div v-for="(sgp,index) in selectGatheringRecords" :key="index">
        <el-row class="f-mt5 f-mb10">
          <el-col :span="6">
            <div class="grid-content f-fr">销账方式：</div>
          </el-col>
          <el-col :span="18">
            <div class="grid-content f-fl" v-if="sgp.payType===102001005">手工销账</div>
          </el-col>
          <el-col :span="18">
            <div class="grid-content f-fl" v-if="sgp.payType!==102001005">在线收款</div>
          </el-col>
        </el-row>
        <el-row class="f-mt5 f-mb10">
          <el-col :span="6">
            <div class="grid-content f-fr">收款人：</div>
          </el-col>
          <el-col :span="18">
            <div class="grid-content f-fl">{{sgp.receivedUser}}</div>
          </el-col>
        </el-row>
        <el-row class="f-mt5 f-mb10">
          <el-col :span="6">
            <div class="grid-content f-fr">收款金额：</div>
          </el-col>
          <el-col :span="18">
            <div class="grid-content f-fl">{{sgp.receivedMoney}}</div>
          </el-col>
        </el-row>
        <el-row class="f-mt5 f-mb10">
          <el-col :span="6">
            <div class="grid-content f-fr">收款类型：</div>
          </el-col>
          <el-col :span="18">
            <div class="grid-content f-fl">{{sgp.gatheringType}}</div>
          </el-col>
        </el-row>
        <el-row class="f-mt5 f-mb10">
          <el-col :span="6">
            <div class="grid-content f-fr">收款时间：</div>
          </el-col>
          <el-col :span="18">
            <div class="grid-content f-fl">{{sgp.receivedDate}}</div>
          </el-col>
        </el-row>
        <el-row class="f-mt5 f-mb10" v-if="sgp.payType!==102001005">
          <el-col :span="6">
            <div class="grid-content f-fr">支付方式：</div>
          </el-col>
          <el-col :span="18">
            <div class="grid-content f-fl">{{sgp.payTypeName}}</div>
          </el-col>
        </el-row>
        <el-row class="f-mt5 f-mb10">
          <el-col :span="6">
            <div class="grid-content f-fr">备注信息：</div>
          </el-col>
          <el-col :span="18">
            <div class="grid-content f-fl">{{sgp.remark}}</div>
          </el-col>
        </el-row>
        <el-row class="f-mt5 f-mb10">
          <el-col :span="6">
            <div class="grid-content f-fr">交易凭证：</div>
          </el-col>
          <el-col :span="18">
            <div class="grid-content f-fl">
              <img v-for="(image,index) in sgp.imageList" :key="index" width="100%" v-bind:src="image"/>
            </div>
          </el-col>
        </el-row>
        <el-row class="f-mt5 f-mb10" v-if="sgp.serialNumber != null || sgp.serialNumber !== '' ">
          <el-col :span="6">
            <div class="grid-content f-fr">交易流水号：</div>
          </el-col>
          <el-col :span="18">
            <div class="grid-content f-fl">{{sgp.serialNumber}}</div>
          </el-col>
        </el-row>
        <hr>
      </div>
    </el-dialog>
    <!--按月销账窗口-->
    <el-dialog title="按月销账" :visible.sync="accountMonthlyVisiable" size="large" :close-on-click-modal="false">
      <section>
        <search-bar>
          <el-row :data="searchConditions">
            <el-col :span="8">
              <el-form-item label="客户名称">
                <el-select v-model="searchConditions.LIKE_memberUserId"
                           remote
                           :remote-method="searchMemberUsers"
                           @change="searchMemberUsersChange"
                           filterable
                           placeholder="请选择客户">
                  <el-option v-for="(mu,index) in memberUsers" :label="mu.realName"
                             :value-key="mu.userId"
                             :value="mu.userId" :key="index">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="发货人">
                <el-input v-model="searchConditions.LIKE_memberUserName"
                          placeholder="请输入发货人"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="签收月份">
                <el-date-picker
                  v-model="searchConditionsSignMonth"
                  type="month"
                  placeholder="签收月份">
                </el-date-picker>
              </el-form-item>
            </el-col>
          </el-row>
        </search-bar>
        <el-col :span="24">
          <el-button type="primary" style="float: right;margin: 10px;margin-left: 0px" @click="resetCondition">重置
          </el-button>
          <el-button type="primary" style="float: right;margin: 10px" @click="searchMembers"
                     :loading="receivableStaticsMonthlyVisiable">查询
          </el-button>
        </el-col>
        <el-table
          :data="orderReceivableStatisticsTableData2" border
          max-height="600"
          @selection-change="selectionOrderChangeMonthly">
          <el-table-column
            type="selection"
            width="55">
          </el-table-column>
          <el-table-column prop="date" label="订单编号" width="150">
            <template slot-scope="scope">
              <a @click="seOrderClick(scope.row)"
                 style="cursor: pointer;text-decoration:underline;color: #20a0ff">{{scope.row.orderNumber}}</a>
            </template>
          </el-table-column>
          <el-table-column prop="name" label="日期" width="200">
            <template slot-scope="scope">
              下单时间:<label>{{scope.row.createDate.substring(0, 10)}}</label><br>
              发车时间:<label v-if="scope.row.actualDepartureDate != null">{{scope.row.actualDepartureDate.substring(0, 10)}}</label><br>
              签收时间:<label v-if="scope.row.signOffDate !=null">{{scope.row.signOffDate.substring(0, 10)}}</label><br>
            </template>
          </el-table-column>
          <el-table-column prop="memberUserName" label="名称" width="200">
            <template slot-scope="scope">
              客户名称:<label>{{scope.row.memberUserName}}</label><br>
              发货人名称:<label>{{scope.row.shipmentsContactName}}</label>
            </template>
          </el-table-column>
          <el-table-column label="专线组织（承运商）" width="150">
            <template slot-scope="scope">
              专线组织:<label>{{scope.row.currentSpecialLineNames}}</label><br>
              车辆信息:<label>{{scope.row.carInfo}}</label><br>
              司机姓名:<label>{{scope.row.driverName}}</label>
            </template>
          </el-table-column>
          <el-table-column prop="shipmentsAddress" label="地址" width="200">
            <template slot-scope="scope">
              <label><label class="la-sy">起</label>:{{scope.row.shipmentsAddress}}</label><br>
              <label><label class="la-sy">止</label>:{{scope.row.sendAddress}}</label>
            </template>
          </el-table-column>
          <el-table-column prop="taxsheet" label="发票信息"></el-table-column>
          <el-table-column prop="supportValue" label="保价金额">

          </el-table-column>
          <el-table-column prop="collectionDelivery" label="代收货款">
            <template slot-scope="scope">
              <label>{{scope.row.collectionDelivery}}</label><br>
              <label v-if="scope.row.collectionDeliveryStatusName===102004001">待付款</label>
              <label v-if="scope.row.collectionDeliveryStatusName===102004002">已付款</label>
            </template>
          </el-table-column>
          <el-table-column label="状态" width="180">
            <template slot-scope="scope">
              <p class="p-sy">订单状态：{{scope.row.orderStatusName}}</p>
              <p class="p-sy" v-if="scope.row.signOff===101009001">签收状态：未签收</p>
              <p class="p-sy" v-if="scope.row.signOff===101009002">签收状态：已签收</p>
              <p class="p-sy" v-if="scope.row.signOff===101009002">签收时间：<br>{{scope.row.signOffDate}}</p>
              <p class="p-sy" v-if="scope.row.actualDeparture">发车状态：已发车</p>
              <p class="p-sy" v-if="!scope.row.actualDeparture">发车状态：未发车</p>
              <p class="p-sy ">结算方式：{{scope.row.paymentTypeName}}</p>
              <p class="p-sy ">付款方式：{{scope.row.orderPays}}</p>
            </template>
          </el-table-column>
          <el-table-column prop="orderPrice" label="订单结算" width="150">
            <template slot-scope="scope">
              <label>订单金额:{{scope.row.orderPrice.toFixed(2)}}</label><br>
              <label>优惠金额:{{scope.row.couponPrice}}</label><br>
              <label v-if="scope.row.receivedPrice != null">已付金额:{{scope.row.receivedPrice.toFixed(2)}}</label><br>
              <label>支付状态:{{scope.row.payStatusName}}</label><br>
            </template>
          </el-table-column>
        </el-table>
        <el-row v-if="orderReceivableStatisticsTableData2.length > 0">
          <el-col :span="22" style="margin-top: 10px">
            <label>
              总计：
              应收订单总额 <label class="la-sy" v-html="totalYSHtml2"></label>元，
              已收订单总额 <label class="la-sy" v-html="totalYESHtml2"></label>元，
              剩余订单总额 <label class="la-sy" v-html="totalSYHtml2"></label>元
            </label>
            <br>
            <label>
              &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
              应收货代总额 <label class="la-sy" v-html="dstotalYSHtml2"></label>元，
              已收货代总额 <label class="la-sy" v-html="dstotalYESHtml2"></label>元，
              剩余货代总额 <label class="la-sy" v-html="dstotalSYHtml2"></label>元
            </label>
          </el-col>
          <el-col :span="2" style="margin-top: 20px">
            <el-button style="float: right" type="primary" @click="handleAccountMonthly"
                       v-if="totalSYHtml2 !== '0.00' || dstotalSYHtml2 !== '0.00' ">一键销账
            </el-button>
            <el-button style="float: right;margin-right:10px" @click="cancleAccountMonthly">取消</el-button>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-pagination
              :current-page="currentPage2"
              :page-size="pageSize2"
              :page-sizes="[6, 15, 30, 100]"
              @size-change="handleSizeChange2"
              @current-change="handleCurrentChange2"
              layout="total,sizes,prev, pager, next, jumper"
              :total="total2" style="text-align: center">
            </el-pagination>
          </el-col>
        </el-row>
      </section>
    </el-dialog>
    <!--按月销账Dialog-->
    <el-dialog :title="cancelAccountDialogTitle2" :visible.sync="cancelAccountDialog2" size="tiny">
      <el-form ref="cancelAccountForm2" :model="cancelAccountForm2" label-width="80px">
        <el-form-item label="销账项目" prop="gatheringType" :rules="{validator: this.gatheringTypeFun}">
          <el-checkbox-group v-model="gatheringTypes" @change="checkClick2">
            <el-checkbox v-if="totalSYHtml2 != 0" label="0">订单金额</el-checkbox>
            <el-checkbox v-if="dstotalSYHtml2 != 0" label="1">代收货款</el-checkbox>
          </el-checkbox-group>
        </el-form-item>
        <el-form-item label="收款金额">{{totalMoney}}
          <!--<el-input class="f-w70" v-model="cancelAccountForm.rTotal" disabled>{{totalSYHtml}}</el-input>-->
        </el-form-item>
        <el-form-item label="收款人" prop="receivedUser" :rules="[{required: true, message: '请输入收款人', trigger: 'change'}]">
          <el-input class="f-w70" v-model="cancelAccountForm2.receivedUser"></el-input>
        </el-form-item>
        <el-form-item label="收款时间" prop="receivedDate"
                      :rules="{required: true, type: 'date',message: '请选择收款时间', trigger: 'change'}">
          <el-date-picker style="width: 70%"
                          v-model="cancelAccountForm2.receivedDate"
                          type="datetime"
                          placeholder="选择收款时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="备注信息">
          <el-input class="f-w70" type="textarea" v-model="cancelAccountForm2.remark"></el-input>
        </el-form-item>
        <el-form-item label="交易凭证">
          <el-upload class="el-upload-wh"
                     :on-success="handleAvatarSuccess2"
                     action="/api/v2.0/admin/file_upload"
                     ref="upload"
                     :file-list="fileList"
                     list-type="picture-card"
                     :before-upload="beforeAvatarUpload">
            <i class="el-icon-plus"></i>
          </el-upload>
          <el-dialog :visible.sync="dialogVisible" size="tiny">
            <img width="50%" style="width: 40%" :src="dialogImageUrl" alt>
          </el-dialog>
          <label>只能上传jpg/png文件，且文件不超过2M</label>
        </el-form-item>
        <el-form-item>
          <el-button @click="cancelAccountDialog2 = false">取消</el-button>
          <el-button type="primary" @click="saveCancelAccountBtn2">确认</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
    <!--月账单查询并导出窗口-->
    <el-dialog title="月账单导出" :visible.sync="monthlyBillVisiable" size="large" :close-on-click-modal="false">
      <section>
        <search-bar>
          <el-row :data="monthlyBillSearchConditions">
            <el-col :span="6">
              <el-form-item label="请选择客户">
                <el-select v-model="monthlyBillSearchConditions.LIKE_memberUserId"
                           remote
                           :remote-method="searchMemberUsers"
                           @change="searchMemberUsersChange"
                           filterable
                           placeholder="请选择客户">
                  <el-option v-for="(mu,index) in memberUsers" :label="mu.realName"
                             :value-key="mu.userId"
                             :value="mu.userId" :key="index">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="发货人">
                <el-input v-model="monthlyBillSearchConditions.LIKE_memberUserName"
                          placeholder="请输入发货人"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="筛选条件">
                <el-select v-model="exportType" placeholder="请选择导出类别">
                  <el-option
                    v-for="item in exportTypes"
                    :key="item"
                    :value="item"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="月份">
                <el-date-picker
                  v-model="monthlyBillSearchConditions.LIKE_Date"
                  type="month"
                  placeholder="请选择月份">
                </el-date-picker>
              </el-form-item>
            </el-col>
          </el-row>
        </search-bar>
        <el-col :span="24">
          <el-button style="float: left;margin: 10px;" type="primary" @click="exportMonthlyBill"
                     :loading="exportBillLoading">导出
          </el-button>
          <el-button type="primary" style="float: right;margin: 10px;margin-left: 0px"
                     @click="resetMonthlyBillCondition">重置
          </el-button>
          <el-button type="primary" style="float: right;margin: 10px" @click="searchMonthlyReceivables"
                     :loading="billSearchLoading">查询
          </el-button>
        </el-col>
        <el-table
          :data="orderReceivableStatisticsTableData3" border
          max-height="600">
          <el-table-column prop="orderNumber" label="订单号" width="150"></el-table-column>
          <el-table-column prop="confirmTime" label="托运日期" width="130">
            <template slot-scope="scope">
              <label v-if="scope.row.confirmTime != null">{{scope.row.confirmTime.substring(0, 10)}}</label>
              <label v-if="scope.row.confirmTime == null">{{scope.row.confirmTime}}</label>
            </template>
          </el-table-column>
          <el-table-column prop="confirmTime" label="签收日期" width="130">
            <template slot-scope="scope">
              <label
                v-if="scope.row.signOff !== null && scope.row.signOff.signOffDate !== null">{{scope.row.signOff.signOffDate.substring(0, 10)}}</label>
              <!--<label  v-if="scope.row.signOff.signOffDate === null">{{scope.row.signOff.signOffDate}}</label>-->
            </template>
          </el-table-column>
          <el-table-column prop="sendCity" label="到站" width="160">
            <template slot-scope="scope">
              {{scope.row.sendCity}}{{scope.row.sendCounty}}
            </template>
          </el-table-column>
          <el-table-column prop="shipmentsContactName" label="发货人"></el-table-column>
          <el-table-column prop="shipmentsContactPhone" label="发货人电话" width="150"></el-table-column>
          <el-table-column prop="sendContactName" label="收货人" width="150"></el-table-column>
          <el-table-column prop="cargoNames" label="货物名称" width="150">
            <!--<template slot-scope="scope">-->
            <!--<label v-for="oc in scope.row.orderCargos">{{oc.cargoName}} + ","</label>-->
            <!--</template>-->
          </el-table-column>
          <el-table-column prop="amount" label="件数"></el-table-column>
          <el-table-column label="重量T">
            <template slot-scope="scope">{{scope.row.weight.toFixed(2)}}</template>
          </el-table-column>
          <el-table-column label="体积m3" width="150px">
            <template slot-scope="scope">{{scope.row.volume.toFixed(2)}}</template>
          </el-table-column>
          <el-table-column prop="paymentTypeName" label="结算方式" width="100"></el-table-column>
          <el-table-column prop="orderPrice" label="现付款" width="100">
            <template slot-scope="scope">
              <label v-if="scope.row.paymentTypeName == '现付'">{{scope.row.orderPrice}}</label>
            </template>
          </el-table-column>
          <el-table-column prop="orderPrice" label="回付款" width="100">
            <template slot-scope="scope">
              <label
                v-if="scope.row.paymentTypeName != '现付' && scope.row.paymentTypeName != '到付'">{{scope.row.orderPrice}}</label>
            </template>
          </el-table-column>
          <el-table-column prop="orderPrice" label="到付款" width="100">
            <template slot-scope="scope">
              <label v-if="scope.row.paymentTypeName == '到付'">{{scope.row.orderPrice}}</label>
            </template>
          </el-table-column>
          <el-table-column prop="collectPaymentAmount" label="代收款" width="100"></el-table-column>
          <el-table-column prop="messageServiceMoney" label="信息费" width="100"></el-table-column>
          <el-table-column label="应付金额" width="100">
            <template slot-scope="scope">
              <label
                v-if="scope.row.paymentTypeName == '现付' || scope.row.paymentTypeName == '到付'">{{(-scope.row.collectPaymentAmount - scope.row.messageServiceMoney).toFixed(2)}}</label>
              <label
                v-if="scope.row.paymentTypeName != '现付' && scope.row.paymentTypeName != '到付'">{{(scope.row.orderPrice - scope.row.collectPaymentAmount - scope.row.messageServiceMoney).toFixed(2)}}</label>
            </template>
          </el-table-column>
        </el-table>
        <el-row :span="24">
          <el-col :span="22" style="margin-top: 10px">
            <label>
              总计：
              总数量 <label class="la-sy">{{totalAmount}}</label>件，
              总重量 <label class="la-sy">{{totalWeight}}</label>T，
              总体积 <label class="la-sy">{{totalVolume}}</label>m3，
              现付款总额<label class="la-sy">{{totalNowPay}}</label>元，
              回付款总额<label class="la-sy">{{totalOtherPay}}</label>元，
              到付款总额<label class="la-sy">{{totalToPay}}</label>元，
              代收款总额<label class="la-sy">{{totalCollectMoney}}</label>元，
              信息费总额<label class="la-sy">{{totalMessageMoney}}</label>元
            </label>
            <br>
            <label>
              应付金额总计：<label class="la-sy">{{totalPay}}</label>元
            </label>
          </el-col>
          <el-col :span="24">
            <el-pagination
              :current-page="currentPage3"
              :page-size="pageSize3"
              @size-change="handleSizeChange3"
              @current-change="handleCurrentChange3"
              layout="total,sizes,prev, pager, next, jumper"
              :total="total3" style="float: right">
            </el-pagination>
          </el-col>
        </el-row>
      </section>
    </el-dialog>
  </div>
</template>

<script>
import {
  getOrderReceivableStatistics,
  saveOrderReceivableStatistics,
  getOrderPayStatistics,
  saveOrderReceivableStatisticsMonthly,
  getOrderReceivableStatisticsMonthlyBill
} from '../../api/order/orderReceivable.js';
import { isEmpty, getSelectObect, objToFilter } from '../../lib/util.js';
import OrderSelect from '../order/OrderSelectDialog.vue';
import { aliPay, accountPay, unionPay, wechatPay } from '../../api/pay/pay.js';
import { getMemberUsers } from '../../api/customer/maintain.js';
// getOrderReceivableStatisticsMonthlyBillBySign, getOrderReceivableStatisticsMonthly,
export default {
  components: {
    'order-select': OrderSelect
  },
  data () {
    return {
      orderPayments: 'all',
      fs: '',
      orderReceivableStatisticsTableData: [],
      selectRows: [],
      seYSHtml: 0, // 当前选中应收总额
      seYESHtml: 0, // 当前选中已收总额
      seSYHtml: 0, // 当前选中剩余总额

      dsseYSHtml: 0, // 当前选中代收应收总额
      dsseYESHtml: 0, // 当前选中代收已收总额
      dsseSYHtml: 0, // 当前选中代收剩余总额

      totalYSHtml: 0, // 应收总额
      totalYESHtml: 0, // 已收总额
      totalSYHtml: 0, // 剩余总额

      dstotalYSHtml: 0, // 应收代收总额
      dstotalYESHtml: 0, // 已收代收总额
      dstotalSYHtml: 0, // 剩余代收总额
      orderSelect: false,
      cancelAccountDialog: false,
      selectGatheringRecordDialog: false,
      selectGatheringRecords: [],
      cancelAccountDialogTitle: '销账',
      gatheringTypes: [],
      fileList: [],
      cancelAccountData: {},
      accountMonthlyVisiable: false, // 按月销账窗口
      memberUsers: [], //
      searchConditions: {
        LIKE_memberUserId: '',
        signOffDate: null,
        LIKE_memberUserName: ''
      },
      cancelAccountDialog2: false,
      cancelAccountDialogTitle2: '按月销账',
      totalYSHtml2: 0,
      totalYESHtml2: 0,
      totalSYHtml2: 0,
      dstotalYSHtml2: 0,
      dstotalYESHtml2: 0,
      dstotalSYHtml2: 0,
      totalYSHtmlMon: 0,
      totalYESHtmlMon: 0,
      totalSYHtmlMon: 0,
      dstotalYSHtmlMon: 0,
      dstotalYESHtmlMon: 0,
      dstotalSYHtmlMon: 0,
      totalMoney: 0,
      accountMonthlys: [],
      actureTotal: 0,
      searchConditionsSignMonth: null,
      orderReceivableStatisticsTableData2: [],
      monthlyBillVisiable: false, // 月账单窗口
      monthlyBillSearchConditions: {
        LIKE_memberUserId: '',
        LIKE_memberUserName: '',
        LIKE_Date: ''
      },
      totalAmount: 0,
      totalWeight: 0,
      totalVolume: 0,
      totalNowPay: 0,
      totalToPay: 0,
      totalOtherPay: 0,
      totalCollectMoney: 0,
      totalMessageMoney: 0,
      totalPay: 0,
      orderReceivableStatisticsTableData3: [],
      cargosNames: '',
      exportTypes: [
        '按确认日期导出',
        '按签收日期导出'
      ],
      label: '',
      billSearchLoading: false,
      receivableStaticsMonthlyVisiable: false,
      exportBillLoading: false,
      monthlySels: [],
      exportType: '',
      currentPage2: 1,
      pageSize2: 6,
      total2: 0,
      currentPage3: 1,
      pageSize3: 10,
      total3: 0,
      cancelAccountForm: {
        orderId: '',
        userId: '',
        userName: '',
        receivableType: '',
        gatheringType: '', // 收款类型（订单金额/代收货款）
        receivableMoney: '', // 应收金额
        receivedMoney: '', // 已收金额
        receivedDate: '', // 收款时间
        receivedUser: '', // 收款人
        payType: 102001005, // 支付方式-销账
        images: '', // 支付方式-销账
        remark: '', // 备注
        rTotal: '' // 总额
      },
      cancelAccountForm2: {
        orderId: '',
        userId: '',
        userName: '',
        receivableType: '',
        gatheringType: '', // 收款类型（订单金额/代收货款）
        receivableMoney: '', // 应收金额
        receivedMoney: '', // 已收金额
        receivedDate: '', // 收款时间
        receivedUser: '', // 收款人
        payType: 102001005, // 支付方式-销账
        images: '', // 支付方式-销账
        remark: '', // 备注
        rTotal: '' // 总额
      },
      models: [],
      orderSelectForm: {},
      paymentConfirmationDialog: false,
      dialogImageUrl: '',
      dialogVisible: false,
      QRCodehtml: '',
      orderNumberPayHtml: '',
      orderFreight: 0,
      orderPaymentType: '',
      collectPaymentAmount: 0,
      orderTotalMoney: '',
      wechatQRCodeDialog: false,
      orderPayRadio: '',
      collection: false,
      support: false,
      clickRow: {},
      selectRow: {},
      searchForm: {},
      total: 0,
      currentPage: 1,
      pageSize: 6
    };
  },
  methods: {
    exportOrderReceivableStatisticsData () {
      if (this.selectRows.length === 0) {
        this.$confirm('确认导出当前所有查询结果?', '提示', {
          type: 'warning'
        }).then(() => {
          location.href = '/api/v2.0/admin/orders/receivable/export?filters=' + this.fs + '&size=' + this.total;
        });
      } else {
        let orderStaticsIds = 'orderStaticsIds=';
        for (let p in this.selectRows) {
          orderStaticsIds += this.selectRows[p].orderNumber + ',';
        }
        this.$confirm('确认导出当前选中项?', '提示', {
          type: 'warning'
        }).then(() => {
          location.href = '/api/v2.0/admin/orders/receivable/export?filters=' + orderStaticsIds + '&size=' + this.selectRows.length;
        });
      }
    },
    selectGatheringRecord (row) {
      this.selectGatheringRecordDialog = true;
      getOrderPayStatistics(row.id).then((res) => {
        if (res.data.successFlg) {
          this.selectGatheringRecords = res.data.detailModelList;
        }
      });
    },
    /**
       * 重置查询条件
       */
    resetSearch () {
      this.collection = false;
      this.support = false;
      this.$refs.ueSearchBar.reset();
    },
    /**
       * 多条件检索订单信息
       */
    resetSearchOrders () {
      this.currentPage = 1;
      this.searchOrders(this.fs = '');
    },
    searchOrders (val) {
      if (isEmpty(val)) {
        val = '';
      }
      let filters = val;
      let ob = Object.assign({}, this.searchForm);
      if (!isEmpty(ob.EQ_invoiceType)) {
        let iv = '';
        if (ob.EQ_invoiceType === 102013001) {
          iv = 101002005;
        }
        if (ob.EQ_invoiceType === 102013002) {
          iv = 101002006;
        }
        if (ob.EQ_invoiceType === 102013003) {
          iv = 101002007;
        }
        filters = filters + 'IN_addValues.dictValue=' + iv + ';';
        delete ob.EQ_invoiceType;
      }
      if (!isEmpty(ob.EQ_isDepart)) {
        if (ob.EQ_isDepart === 111002001) {
          filters = filters + 'IN_trunkTasks.loadingListTrunkTask.loadingListRoute.loadingList.status=105007004,105007005,105007006,105007007;';
        } else if (ob.EQ_isDepart === 111002002) {
          filters = filters + 'IN_trunkTasks.loadingListTrunkTask.loadingListRoute.loadingList.status=105007001,105007002,105007003;';
        }
        delete ob.EQ_isDepart;
      }
      filters = filters + objToFilter(ob);
      if (this.collection && !this.support) {
        filters = filters + ';EQ_addValues.dictValue=101002002;ISNOTNULL_addValues.value;';
      }
      if (this.support && !this.collection) {
        filters = filters + ';EQ_addValues.dictValue=101002001;ISNOTNULL_addValues.value;';
      }
      if (this.collection && this.support) {
        filters = filters + 'IN_addValues.dictValue=101002001,101002002;ISNOTNULL_addValues.value;';
      }
      this.fs = filters = 'NOTIN_orderStatus=101001001,101001002,101001012;EQ_isDelete=111002002;' + filters + ';';
      this.searchOrderReceivableStatistics(filters);
    },
    gatheringTypeFun (rule, value, callback) {
      let va = this.gatheringTypes;
      if (va == null) {
        return callback(new Error('至少选择一项才能保存'));
      }
      callback();
    },
    handleAvatarSuccess (res, file) {
      if (res.successFlg) {
        this.cancelAccountForm.images = isEmpty(this.cancelAccountForm.images) ? res.obj + ',' : this.cancelAccountForm.images + res.obj + ',';
      } else {
        this.$message.error('图片上传异常！请重新选择');
      }
    },
    beforeAvatarUpload (file) {
      const isJPG = file.type === 'image/jpeg' || file.type === 'image/png';
      const isLt2M = file.size / 1024 / 1024 < 2;

      if (!isJPG) {
        this.$message.error('上传头像图片只能是 JPG 和 png格式!');
      }
      if (!isLt2M) {
        this.$message.error('上传头像图片大小不能超过 2MB!');
      }
      return isJPG && isLt2M;
    },
    saveCancelAccountBtn () {
      this.$refs['cancelAccountForm'].validate((cancelAccountFormValid) => {
        if (cancelAccountFormValid) {
          let isChangeStatus = false;
          if (isEmpty(this.clickRow.collectionDelivery)) {
            isChangeStatus = true;
          }
          if (this.models.length === 1) {
            // 如果选择的是代收货款，判断订单金额是否支付
            if (this.models[0].receivableType === 101005006) {
              // 如果订单金额已付款，则改变订单和签收点的支付状态
              if (this.clickRow.orderPricePayStatus === 102004002) {
                isChangeStatus = true;
              }
            } else {
              // 否则 判断代收货款是否支付
              if (this.clickRow.collectionDeliveryStatusName === 102004002) {
                isChangeStatus = true;
              }
            }
          }
          this.models.forEach(m => {
            m.changeStatus = isChangeStatus;
            m.orderId = this.clickRow.id;
            m.orderNumber = this.clickRow.orderNumber;
            m.userId = this.clickRow.memberUserId;
            m.userName = this.clickRow.memberUserName;
            m.receivedDate = this.cancelAccountForm.receivedDate;
            m.receivedUser = this.cancelAccountForm.receivedUser;
            m.payType = 102001005;
            m.images = this.cancelAccountForm.images;
            m.remark = this.cancelAccountForm.remark;
          });
          saveOrderReceivableStatistics(JSON.stringify(this.models)).then((res) => {
            if (res.data.successFlg) {
              this.$message.success('销账成功');
              this.searchOrders('');
              this.cancelAccountDialog = false;
            } else {
              this.$message.error('销账异常');
            }
          });
        }
      });
    },
    checkClick (val) {
      let row = this.clickRow;
      let total = 0;
      this.models = [];
      val.forEach(k => {
        let model = {};
        if (k === '0') {
          total = total + row.orderPrice;
          model.receivableType = this.clickRow.paymentType;
          model.gatheringType = '订单金额';
          model.receivableMoney = row.orderPrice;
          model.receivedMoney = row.orderPrice;
        }
        if (k === '1') {
          total = total + row.collectionDelivery;
          model.receivableType = 101005006;
          model.gatheringType = '代收货款';
          model.receivableMoney = row.collectionDelivery;
          model.receivedMoney = row.collectionDelivery;
        }
        this.models.push(model);
      });
      this.cancelAccountForm.rTotal = total.toFixed(2);
    },
    cancelAccountClick (row) {
      this.fileList = [];
      this.gatheringTypes = [];
      if (this.$refs.cancelAccountForm) {
        this.$refs.cancelAccountForm.resetFields();
      }
      for (let p in this.cancelAccountForm) {
        if (this.cancelAccountForm[p] instanceof Array) {
          this.cancelAccountForm[p] = [];
        } else {
          this.cancelAccountForm[p] = null;
        }
      }
      this.clickRow = row;
      this.cancelAccountDialogTitle = '销账 > ' + row.orderNumber;
      this.cancelAccountDialog = true;
    },
    paymentAffirms () {
      localStorage.setItem('back_url', this.$route.path);
      let orderId = this.selectRow.id;
      switch (this.orderPayRadio) {
        case 'accountPay':
          accountPay({
            orderId: orderId, // 订单id
            couponId: '', // 优惠券id
            couponUseId: ''// 优惠券领用id
          }).then((res) => {
            window.document.write(res.data);
          });
          break;
        case 'aliPay':
          aliPay({
            orderId: orderId, // 订单id
            couponId: '', // 优惠券id
            couponUseId: ''// 优惠券领用id
          }).then((res) => {
            console.log(res.data);
            window.document.write(res.data);
          });
          break;
        case 'weChatPay':
          wechatPay({
            orderId: orderId, // 订单id
            couponId: '', // 优惠券id
            couponUseId: ''// 优惠券领用id
          }).then((res) => {
            this.wechatQRCodeDialog = true;
            let com = 'http://qr.liantu.com/api.php?text=';
            let url = com + res.data.obj.codeUrl;
            this.QRCodehtml = '<img style="width: 100%;margin: auto" src=' + url + ' />';
            this.stopPayWeChat = setInterval(() => {
              console.log(res.data.obj.serialNo);
              this.refreshOrderPayWeChat(res.data.obj.serialNo);
            }, 5000);
          });
          break;
        case 'unionPay':
          unionPay({
            orderId: orderId, // 订单id
            couponId: '', // 优惠券id
            couponUseId: ''// 优惠券领用id
          }).then((res) => {
            console.log(res.data);
            window.document.write(res.data);
          });
          break;
      }
    },
    paymentConfirmation (row) {
      this.selectRow = row;
      let total = 0;
      this.orderFreight = 0;
      this.collectPaymentAmount = 0;
      if (row.orderPricePayStatus === 102004001) {
        total = row.orderPrice;
        this.orderFreight = row.orderPrice;
      }
      if (!isEmpty(row.collectionDelivery) && row.collectionDeliveryStatusName === 102004001) {
        total += row.collectionDelivery;
        this.collectPaymentAmount = row.collectionDelivery;
      }
      this.paymentConfirmationDialog = true;
      this.orderNumberPayHtml = row.orderNumber;
      this.orderPaymentType = row.paymentTypeName;
      this.orderTotalMoney = total;
    },

    seOrderClick (val) {
      this.orderSelect = true;
      this.orderSelectForm = val;
    },
    selectionOrderChange (val) {
      this.selectRows = val;
      let seYSHtml = 0; // 当前选中应收总额
      let seYESHtml = 0; // 当前选中已收总额
      let seSYHtml = 0; // 当前选中剩余总额

      let dsseYSHtml = 0; // 当前选中代收应收总额
      let dsseYESHtml = 0; // 当前选中代收已收总额
      let dsseSYHtml = 0; // 当前选中代收剩余总额

      val.map(row => {
        if (!isEmpty(row.orderPrice)) {
          seYSHtml = seYSHtml + parseFloat(row.orderPrice);
        }
        if (!isEmpty(row.receivedPrice)) {
          seYESHtml = seYESHtml + parseFloat(row.receivedPrice);
        }

        if (!isEmpty(row.collectionDelivery)) {
          dsseYSHtml = dsseYSHtml + parseFloat(row.collectionDelivery);
        }

        if (row.collectionDeliveryStatusName === 102004002 && !isEmpty(row.collectionDelivery)) {
          dsseYESHtml = dsseYESHtml + parseFloat(row.collectionDelivery);
        }

        seSYHtml = seYSHtml - seYESHtml;
        dsseSYHtml = dsseYSHtml - dsseYESHtml;
      });
      this.seYSHtml = seYSHtml.toFixed(2);
      this.seYESHtml = seYESHtml.toFixed(2);
      this.seSYHtml = seSYHtml.toFixed(2);

      this.dsseYSHtml = dsseYSHtml.toFixed(2);
      this.dsseYESHtml = dsseYESHtml.toFixed(2);
      this.dsseSYHtml = dsseSYHtml.toFixed(2);
    },
    searchOrderReceivableStatistics (filters) {
      getOrderReceivableStatistics({
        filters: filters,
        sorts: '-createDate',
        size: this.pageSize,
        page: this.currentPage
      }).then((res) => {
        this.orderReceivableStatisticsTableData = [];
        this.total = this.totalYSHtml = this.totalYESHtml = this.totalSYHtml = this.dstotalYSHtml = this.dstotalYESHtml = this.dstotalSYHtml = 0;
        if (res.data.successFlg) {
          this.orderReceivableStatisticsTableData = res.data.detailModelList;
          this.currentPage = res.data.currPage;
          this.total = res.data.totalCount;
          this.pageSize = res.data.pageSize;
          this.totalYSHtml = res.data.obj.orderPrice;
          this.totalYESHtml = res.data.obj.receivedPrice;
          this.totalSYHtml = (this.totalYSHtml - this.totalYESHtml).toFixed(2);
          this.dstotalYSHtml = res.data.obj.dsOrderPrice;
          this.dstotalYESHtml = res.data.obj.dsReceivedPrice;
          this.dstotalSYHtml = (this.dstotalYSHtml - this.dstotalYESHtml).toFixed(2);
        }
      });
    },
    activeOrderPaymentsClick (val) {
      if (val === 'all') {
        this.fs = '';
      } else {
        this.fs = 'EQ_paymentType=' + val + ';';
      }
      this.searchOrders(this.fs);
    },
    // 按月销账
    accountMonthly () {
      this.accountMonthlyVisiable = true;
      this.resetCondition();
      this.orderReceivableStatisticsTableData2 = [];
    },
    searchMemberUsersChange (val) {
      getSelectObect(this.searchConditions.LIKE_memberUserId, 'userId', this.memberUsers);
    },
    searchMemberUsers (val) {
      let filters = isEmpty(val) ? 'logicStatus=111002002;status=111002001' : 'logicStatus=111002002;status=111002001;realName?' + val + ' g1';
      getMemberUsers({
        token: this.token,
        filters: filters,
        sorts: '+createDate',
        size: '10',
        page: '1'
      }).then((res) => {
        this.memberUsers = res.data.detailModelList;
      });
    },
    // 一键销账
    handleAccountMonthly () {
      this.fileList = [];
      this.gatheringTypes = [];
      if (this.$refs.cancelAccountForm2) {
        this.$refs.cancelAccountForm2.resetFields();
      }
      for (let p in this.cancelAccountForm2) {
        if (this.cancelAccountForm2[p] instanceof Array) {
          this.cancelAccountForm2[p] = [];
        } else {
          this.cancelAccountForm2[p] = null;
        }
      }
      this.accountMonthlys = this.orderReceivableStatisticsTableData2;
      this.cancelAccountDialog2 = true;
      this.actureTotal = Number(this.totalSYHtml2) + Number(this.dstotalSYHtml2);
      this.totalMoney = 0;
    },
    cancleAccountMonthly () {
      this.accountMonthlyVisiable = false;
      this.searchOrderReceivableStatistics('');
    },
    // 按条件查询会员应收记录
    searchMembers () {
      if ((this.searchConditions.LIKE_memberUserId === null || this.searchConditions.LIKE_memberUserId === '' || this.searchConditions.LIKE_memberUserId === undefined) && (this.searchConditions.LIKE_memberUserName === null || this.searchConditions.LIKE_memberUserName === '' || this.searchConditions.LIKE_memberUserName === undefined)) {
        this.$message.error('请选择客户或发货人！');
        return;
      }
      this.receivableStaticsMonthlyVisiable = true;
      let filters = 'NOTEQ_orderStatus=101001001;NOTEQ_orderStatus=101001002;EQ_isDelete=111002002;';
      if (this.searchConditions.LIKE_memberUserId !== null && this.searchConditions.LIKE_memberUserId !== '' && this.searchConditions.LIKE_memberUserId !== undefined) {
        filters += 'EQ_memberUserId=' + this.searchConditions.LIKE_memberUserId + ';';
      }
      if (this.searchConditions.LIKE_memberUserName !== null && this.searchConditions.LIKE_memberUserName !== '' && this.searchConditions.LIKE_memberUserName !== undefined) {
        filters += 'LIKE_shipmentsContactName=' + this.searchConditions.LIKE_memberUserName + ';';
      }
      let date = '';
      if (this.searchConditionsSignMonth !== null && this.searchConditionsSignMonth !== '' && this.searchConditionsSignMonth !== undefined) {
        date = this.searchConditionsSignMonth.toJSON();
        let date2 = this.$ue.addMonths(this.searchConditionsSignMonth, 1).toJSON();
        filters += 'GT_signOff.signOffDate=' + date + ';LT_signOff.signOffDate=' + date2;
      }
      getOrderReceivableStatistics({
        filters: filters,
        page: this.currentPage2,
        size: this.pageSize2
      }).then((res) => {
        if (res.data.successFlg) {
          this.receivableStaticsMonthlyVisiable = false;
          this.orderReceivableStatisticsTableData2 = res.data.detailModelList;
          this.totalYSHtmlMon = this.totalYSHtml2 = res.data.obj.orderPrice;
          this.totalYESHtmlMon = this.totalYESHtml2 = res.data.obj.receivedPrice;
          this.totalSYHtmlMon = this.totalSYHtml2 = (this.totalYSHtml2 - this.totalYESHtml2).toFixed(2);
          this.dstotalYSHtmlMon = this.dstotalYSHtml2 = res.data.obj.dsOrderPrice;
          this.dstotalYESHtmlMon = this.dstotalYESHtml2 = res.data.obj.dsReceivedPrice;
          this.dstotalSYHtmlMon = this.dstotalSYHtml2 = (this.dstotalYSHtml2 - this.dstotalYESHtml2).toFixed(2);
          this.currentPage2 = res.data.currPage;
          this.total2 = res.data.totalCount;
          this.pageSize2 = res.data.pageSize;
        }
      });
    },
    checkClick2 (val) {
      let total = Number(0);
      val.forEach(o => {
        if (o === '0') {
          total = Number(total) + Number(this.totalSYHtml2);
        }
        if (o === '1') {
          total = Number(total) + Number(this.dstotalSYHtml2);
        }
      });
      this.totalMoney = total.toFixed(2);
      this.cancelAccountForm2.rTotal = total.toFixed(2);
      this.models = [];
      let actTableList = [];
      if (this.monthlySels.length < 1) {
        actTableList = this.orderReceivableStatisticsTableData2;
      } else {
        actTableList = this.monthlySels;
      }
      val.forEach(k => {
        let model = {};
        if (k === '0') {
          actTableList.forEach(o => {
            if (o.orderPrice !== 0 && o.orderPrice !== null) {
              model = {};
              model.receivableType = o.paymentType;
              model.gatheringType = '订单金额';
              model.receivableMoney = o.orderPrice;
              model.receivedMoney = o.orderPrice;
              model.orderId = o.id;
              model.orderNumber = o.orderNumber;
              model.userId = o.memberUserId;
              model.userName = o.memberUserName;
              model.orderPricePayStatus = o.orderPricePayStatus; // 订单金额付款状态
              model.collectionDeliveryStatusName = o.collectionDeliveryStatusName; // 代收货款支付状态
              model.collectionDelivery = o.collectionDelivery; // 代收货款
              this.models.push(model);
            }
          });
        }
        if (k === '1') {
          actTableList.forEach(o => {
            if (o.collectionDelivery !== 0 && o.collectionDelivery !== null) {
              model = {};
              model.receivableType = 101005006;
              model.gatheringType = '代收货款';
              model.receivableMoney = o.collectionDelivery;
              model.receivedMoney = o.collectionDelivery;
              model.orderId = o.id;
              model.orderNumber = o.orderNumber;
              model.userId = o.memberUserId;
              model.userName = o.memberUserName;
              model.orderPricePayStatus = o.orderPricePayStatus; // 订单金额付款状态
              model.collectionDeliveryStatusName = o.collectionDeliveryStatusName; // 代收货款支付状态
              model.collectionDelivery = o.collectionDelivery; // 代收货款
              this.models.push(model);
            }
          });
        }
      });
    },
    saveCancelAccountBtn2 () {
      this.$refs['cancelAccountForm2'].validate((valid) => {
        if (valid) {
          this.models.forEach(m => {
            let isChangeStatus = false;
            m.receivedDate = this.cancelAccountForm2.receivedDate;
            m.receivedUser = this.cancelAccountForm2.receivedUser;
            m.payType = 102001005;
            m.images = this.cancelAccountForm2.images;
            m.remark = this.cancelAccountForm2.remark;
            // 代收货款销账，并且该条应收记录的订单金额支付状态为已支付
            if (m.orderPricePayStatus === 102004002 && m.gatheringType === '代收货款') {
              isChangeStatus = true;
            }
            // 订单金额销账，并且该条应收记录的订单代收货款支付状态为已支付
            if (m.collectionDeliveryStatusName === 102004002 && m.gatheringType === '订单金额') {
              isChangeStatus = true;
            }
            // 订单金额销账，并且该订单无代收货款
            if (m.gatheringType === '订单金额' && m.collectionDelivery === null) {
              isChangeStatus = true;
            }
            // 如果表单提交的支付金额=（实际应付的订单金额+代收货款），后台支付状态改为已支付
            let self = this;
            if (self.cancelAccountForm2.rTotal === self.actureTotal) {
              isChangeStatus = true;
            }
            m.changeStatus = isChangeStatus;
          });
          saveOrderReceivableStatisticsMonthly(JSON.stringify(this.models)).then((res) => {
            if (res.data.successFlg) {
              this.$message.success('销账成功');
              this.cancelAccountDialog2 = false;
              this.accountMonthlyVisiable = false;
              this.searchOrderReceivableStatistics('');
            } else {
              this.$message.error('销账异常');
            }
          });
        }
      });
    },
    handleAvatarSuccess2 (res, file) {
      if (res.successFlg) {
        this.cancelAccountForm2.images = isEmpty(this.cancelAccountForm2.images) ? res.obj + ',' : this.cancelAccountForm.images + res.obj + ',';
      } else {
        this.$message.error('图片上传异常！请重新选择');
      }
    },
    // 重置查询条件
    resetCondition () {
      this.searchConditions.memberUserId = null;
      this.searchConditionsSignMonth = null;
      this.searchConditions.LIKE_memberUserName = null;
      this.orderReceivableStatisticsTableData2 = [];
      this.monthlySels = [];
      this.$ue.resetObjNull(this.searchConditions);
    },
    // 月账单导出窗口
    monthlyBillExport () {
      this.label = '';
      this.currentPage3 = 1;
      this.monthlyBillVisiable = true;
      this.orderReceivableStatisticsTableData3 = [];
      this.resetMonthlyBillCondition();
      this.totalAmount = 0;
      this.totalWeight = 0;
      this.totalVolume = 0;
      this.totalNowPay = 0;
      this.totalOtherPay = 0;
      this.totalToPay = 0;
      this.totalCollectMoney = 0;
      this.totalMessageMoney = 0;
      this.totalPay = 0;
    },
    // 查询月账单对应应收记录
    searchMonthlyReceivables () {
      if (this.monthlyBillSearchConditions.LIKE_memberUserId === null && this.monthlyBillSearchConditions.LIKE_memberUserName === null) {
        this.$message.error('请选择客户或签收人！');
        return;
      }
      if (this.monthlyBillSearchConditions.LIKE_Date !== '' && this.monthlyBillSearchConditions.LIKE_Date !== null && this.monthlyBillSearchConditions.LIKE_Date !== undefined && this.exportType === '') {
        this.$message.error('请选择筛选条件！');
        return;
      }
      if ((this.monthlyBillSearchConditions.LIKE_Date === '' || this.monthlyBillSearchConditions.LIKE_Date === null || this.monthlyBillSearchConditions.LIKE_Date === undefined) && this.exportType !== '') {
        this.$message.error('请选择查询时间！');
        return;
      }
      let filters = '';
      if (this.monthlyBillSearchConditions.LIKE_memberUserId !== null && this.monthlyBillSearchConditions.LIKE_memberUserId !== '') {
        filters += 'EQ_memberUserId=' + this.monthlyBillSearchConditions.LIKE_memberUserId + ';';
      }
      if (this.monthlyBillSearchConditions.LIKE_memberUserName !== null && this.monthlyBillSearchConditions.LIKE_memberUserName !== '') {
        filters += 'LIKE_shipmentsContactName=' + this.monthlyBillSearchConditions.LIKE_memberUserName + ';';
      }
      if (this.exportType !== null && this.exportType !== '' && this.monthlyBillSearchConditions.LIKE_Date !== null && this.monthlyBillSearchConditions.LIKE_Date !== undefined && this.monthlyBillSearchConditions.LIKE_Date !== '') {
        if (this.exportType === '按确认日期导出') {
          let date1 = this.monthlyBillSearchConditions.LIKE_Date;
          filters += 'GT_confirmTime=' + date1.toJSON() + ';';
          let tool = date1;
          let date2 = this.$ue.addMonths(tool, 1);
          filters += 'LT_confirmTime=' + date2.toJSON() + ';';
        }
        if (this.exportType === '按签收日期导出') {
          let date1 = this.monthlyBillSearchConditions.LIKE_Date;
          filters += 'GT_signOff.signOffDate=' + date1.toJSON() + ';';
          let tool = date1;
          let date2 = this.$ue.addMonths(tool, 1);
          filters += 'LT_signOff.signOffDate=' + date2.toJSON() + ';';
        }
      }
      this.billSearchLoading = true;
      getOrderReceivableStatisticsMonthlyBill({
        filters: filters,
        page: this.currentPage3,
        size: this.pageSize3,
        label: this.label
      }).then((res) => {
        if (res.data.successFlg) {
          this.billSearchLoading = false;
          this.orderReceivableStatisticsTableData3 = res.data.detailModelList;
          this.currentPage3 = res.data.currPage;
          this.total3 = res.data.totalCount;
          this.pageSize3 = res.data.pageSize;
          this.orderReceivableStatisticsTableData3.forEach(o => {
            o.orderCargos.forEach(c => {
              // o.object() += c.cargoName;
            });
          });
          if (this.label !== '分页') {
            let strings = res.data.obj.remark;
            let totalMes = strings.split(';');
            totalMes.forEach(o => {
              let keyValue = o.split('=');
              let key = keyValue[0];
              let value = keyValue[1];
              if (key === 'nowPay') {
                this.totalNowPay = value;
              }
              if (key === 'toPay') {
                this.totalToPay = value;
              }
              if (key === 'collectMoney') {
                this.totalCollectMoney = value;
              }
              if (key === 'messageMoney') {
                this.totalMessageMoney = value;
              }
              if (key === 'totalAmount') {
                this.totalAmount = value;
              }
              if (key === 'totalVolume') {
                this.totalVolume = value;
              }
              if (key === 'totalWeight') {
                this.totalWeight = value;
              }
              if (key === 'otherPay') {
                this.totalOtherPay = value;
              }
              if (key === 'totalPay') {
                this.totalPay = value;
              }
            });
          }
          this.label = '';
        }
      });
    },
    selectionOrderChangeMonthly (val) {
      this.monthlySels = val;
      if (this.monthlySels.length > 0) {
        let totalYSHtml2 = 0; // 当前选中应收总额
        let totalYESHtml2 = 0; // 当前选中已收总额
        let totalSYHtml2 = 0; // 当前选中剩余总额

        let dstotalYSHtml2 = 0; // 当前选中代收应收总额
        let dstotalYESHtml2 = 0; // 当前选中代收已收总额
        let dstotalSYHtml2 = 0; // 当前选中代收剩余总额
        val.map(row => {
          if (!isEmpty(row.orderPrice)) {
            totalYSHtml2 = totalYSHtml2 + parseFloat(row.orderPrice);
          }
          if (!isEmpty(row.receivedPrice)) {
            totalYESHtml2 = totalYESHtml2 + parseFloat(row.receivedPrice);
          }

          if (!isEmpty(row.collectionDelivery)) {
            dstotalYSHtml2 = dstotalYSHtml2 + parseFloat(row.collectionDelivery);
          }

          if (row.collectionDeliveryStatusName === 102004002 && !isEmpty(row.collectionDelivery)) {
            dstotalYESHtml2 = dstotalYESHtml2 + parseFloat(row.collectionDelivery);
          }

          totalSYHtml2 = totalYSHtml2 - totalYESHtml2;
          dstotalSYHtml2 = dstotalYSHtml2 - dstotalYESHtml2;
        });
        this.totalYSHtml2 = totalYSHtml2.toFixed(2);
        this.totalYESHtml2 = totalYESHtml2.toFixed(2);
        this.totalSYHtml2 = totalSYHtml2.toFixed(2);

        this.dstotalYSHtml2 = dstotalYSHtml2.toFixed(2);
        this.dstotalYESHtml2 = dstotalYESHtml2.toFixed(2);
        this.dstotalSYHtml2 = dstotalSYHtml2.toFixed(2);
      } else {
        this.totalYSHtml2 = this.totalYSHtmlMon;
        this.totalYESHtml2 = this.totalYESHtmlMon;
        this.totalSYHtml2 = this.totalSYHtmlMon;

        this.dstotalYSHtml2 = this.dstotalYSHtmlMon;
        this.dstotalYESHtml2 = this.dstotalYESHtmlMon;
        this.dstotalSYHtml2 = this.dstotalSYHtmlMon;
      }
    },
    // 重置月账单查询条件
    resetMonthlyBillCondition () {
      this.monthlyBillSearchConditions.LIKE_memberUserName = null;
      this.monthlyBillSearchConditions.LIKE_memberUserId = null;
      this.monthlyBillSearchConditions.LIKE_Date = null;
      this.exportType = '';
      this.orderReceivableStatisticsTableData3 = [];
      this.$ue.resetObjNull(this.monthlyBillSearchConditions);
      this.totalAmount = 0;
      this.totalWeight = 0;
      this.totalVolume = 0;
      this.totalNowPay = 0;
      this.totalOtherPay = 0;
      this.totalToPay = 0;
      this.totalCollectMoney = 0;
      this.totalMessageMoney = 0;
      this.totalPay = 0;
      this.total3 = 0;
      this.currentPage3 = 1;
      this.label = '';
    },
    exportMonthlyBill () {
      this.exportBillLoading = true;
      let filters = '';
      if (this.monthlyBillSearchConditions.LIKE_memberUserId !== null && this.monthlyBillSearchConditions.LIKE_memberUserId !== '') {
        filters += 'EQ_memberUserId=' + this.monthlyBillSearchConditions.LIKE_memberUserId + ';';
      }
      if (this.monthlyBillSearchConditions.LIKE_memberUserName !== null && this.monthlyBillSearchConditions.LIKE_memberUserName !== '') {
        filters += 'LIKE_shipmentsContactName=' + this.monthlyBillSearchConditions.LIKE_memberUserName + ';';
      }
      if (this.exportType !== null && this.exportType !== '' && this.monthlyBillSearchConditions.LIKE_Date !== null && this.monthlyBillSearchConditions.LIKE_Date !== undefined && this.monthlyBillSearchConditions.LIKE_Date !== '') {
        if (this.exportType === '按确认日期导出') {
          let date1 = this.monthlyBillSearchConditions.LIKE_Date;
          filters += 'GT_confirmTime=' + date1.toJSON() + ';';
          let tool = date1;
          let date2 = this.$ue.addMonths(tool, 1);
          filters += 'LT_confirmTime=' + date2.toJSON() + ';';
        }
        if (this.exportType === '按签收日期导出') {
          let date1 = this.monthlyBillSearchConditions.LIKE_Date;
          filters += 'GT_signOff.signOffDate=' + date1.toJSON() + ';';
          let tool = date1;
          let date2 = this.$ue.addMonths(tool, 1);
          filters += 'LT_signOff.signOffDate=' + date2.toJSON() + ';';
        }
      } else {
        this.$message.error('请选择签收/确认月份');
        this.exportBillLoading = false;
        return;
      }
      location.href = '/api/v2.0/admin/orders/monthlebill/export?filters=' + filters + '&date=' + this.monthlyBillSearchConditions.LIKE_Date.toJSON();
      this.exportBillLoading = false;
    },
    // 每页几条操作
    handleSizeChange (val) {
      this.pageSize = val;
      this.searchOrders(this.fs);
    },
    // 第几页操作
    handleCurrentChange (val) {
      console.log('val:' + val);
      console.log('this.fs:' + this.fs);
      this.currentPage = val;
      this.searchOrders(this.fs);
    },
    handleSizeChange2 (val) {
      this.pageSize2 = val;
      this.searchMembers();
    },
    handleCurrentChange2 (val) {
      this.currentPage2 = val;
      this.searchMembers();
    },
    handleSizeChange3 (val) {
      this.pageSize3 = val;
      this.searchMonthlyReceivables();
    },
    handleCurrentChange3 (val) {
      this.label = '分页';
      this.currentPage3 = val;
      this.searchMonthlyReceivables();
    }
  },
  // 初始化js
  mounted () {
    this.resetSearchOrders();
    this.$store.commit('initDict');
    this.$store.commit('initOrganizations');
    this.searchMemberUsers();
  },
  computed: {
    btns () {
      return this.$store.state.btns[this.$route.path] || [];
    },
    querys () {
      return this.$store.state.querys[this.$route.path + '#default'] || [];
    }
  }
};
</script>
